<template>
    <div>
        <el-dialog v-dialogDrag title="编辑数据字典" :visible="editShow" width="40%" @close="dialogClose" :close-on-click-modal="false">
            <el-form ref="editForm" :model="formFileds" :rules="rules" label-width="auto">
                <el-form-item label="标识码：" prop="remark">
                    <el-input type="text" v-model="formFileds.remark" disabled></el-input>
                </el-form-item>
                <el-form-item label="字典名称：" prop="dictName">
                    <el-input type="text" v-model="formFileds.dictName"></el-input>
                </el-form-item>
                <el-form-item label="字典值：" prop="dictValue">
                    <el-input type="text" :rows="3" v-model="formFileds.dictValue"></el-input>
                </el-form-item>
                <!-- <el-form-item label="排序：" prop="index">
                    <el-input type="text" v-model="formFileds.index"></el-input>
                </el-form-item> -->
                <!-- <el-form-item label="父级字典：" prop="parentId">
                    <el-input type="text" v-model="formFileds.parentId"></el-input>
                </el-form-item> -->
                <el-form-item>
                    <el-button type="primary" @click="submitForm()" class="pull-right margin-l-25">确定
                    </el-button>
                    <el-button @click="dialogClose" class="pull-right">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
import { dataDictionaryUpdate } from '@/api/systemManage/dataDictionary';
export default {
    //接受父组件
    props: {
        editShow: {
            type: Boolean
        },
        record: {
            type: Object
        }
    },

    data () {
        return {
            formFileds: {},
            rules: {
                dictName: [{
                    required: true,
                    message: '请输入字典名称',
                    trigger: 'blur'
                }],
                dictValue: [{
                    required: true,
                    message: '请输入字典值',
                    trigger: 'blur'
                }],
                index: [{
                    required: true,
                    message: '请输入排序的值',
                    trigger: 'blur'
                }],
                // parentId: [{
                //     required: true,
                //     message: '请输入该父级字典',
                //     trigger: 'blur'
                // }],
            },
        }
    },
    methods: {
        dialogClose () {
            this.$emit('dialogClose')
        },
        submitForm () {
            this.$refs.editForm.validate((valid) => {
                if (valid) {
                    let params = {}
                    dataDictionaryUpdate(Object.assign(params, this.formFileds)).then((res) => {
                        this.$message.success('操作成功')
                        this.$emit('dialogClose')
                        this.$emit('close')
                    })
                }
                else {
                    return
                }
            });
        },

    },
    mounted () {
        this.formFileds = Object.assign({},this.record);
    }
}
</script>

<style lang="less" scoped>

</style>